package com.atguigu.gmall.payment;


import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest//(classes = ServicePaymentApplication.class)
public class PaymentJunit {

    @Test
    public void test() throws Exception {

        //1:AlipayClient 客户端  接口
        // DefaultAlipayClient 实现类
        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi.alipaydev.com/gateway.do",
                "2016102100732915",
                "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDTMtESbEXbYMAbiDuHObivg09wVF671/sfE4yZCrmIUdAF/JsJS+vsh2JBEkacVE4MQd9uVM9CFuvrvnZ+3oO00+R6fxSonNiVCUHcYENlkv6UD4OTIjzU85enkewHRroTc2LL4820YYXBfCqiqAWWFc4dG0mjdw/TIrvdWSDAelycT1pGw5vFCoXud+IQb278gF8BjQhznG35r3ScptX9W1BY51kkFgAKV0MNt+Ai+8UqQxh3g7970nVQkftWTqFhOx1t2O7QGnWh3OqSFg2f/M/aon8gseibkk9wIZ5J7LyqNM804I5RngWo/wH3EqntdCGp4b6oAMk181SemCbdAgMBAAECggEAG8Ww7IVEYmbEnFo7ybpzaNERnynZE0aBhUKi2HUqlJx9iGwBTyWmroHXD8uBcYk8giwfX3jTkFNHTsbK+j/0fdDnWJxhcRK/AEopWPtnoXHE/F9V5AE6kp49sRFlQkewrGId+cXJBRFV722OhbkmkufnJLiz5EUB1bfZkG/p+KVhQgzMUThEJGeW/0Qc7RC9XgKp6pbe/kGTV/jou+mzHpoAkyur2DPUeSnqt5d67d/YeIvr1H683saQypTD1PSaDwawImmHAI/PPsUlZP7HljcVxHXwjd7LX+JtES39BA4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o5l7YRVnGSyQTq0pQjMFYi/wKGFGHAA37Wl2L/AMaGpT6CJncSqcAJssY61qmz/o9lw+hRq6KBfdktl4xm0d5f+uMgCLKqa6bYbFyG7vNZszGJ6yW2n6fFbZ0B4PgPXfrRFVG+OS204bi7sGDba6DuJPPuk8B/gkVoDkmKHNRnLXZi74jyZROlEXKr8JElZqpT6RODkKAmIRCGlQrAadUntgmymguRlN2K+TfSNIigY1FRekb/BudYhlbA5QIDAQAB",
                "RSA2");
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        Map<String, String> map = new HashMap<>();
        map.put("out_trade_no", "1600227003015");
        map.put("product_code", "FAST_INSTANT_TRADE_PAY");
        map.put("total_amount", "12333.09");
        map.put("subject", "支付宝测试付钱");
        request.setBizContent(JSONObject.toJSONString(map));
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if (response.isSuccess()) {
            System.out.println("调用成功");
            System.out.println(response.getBody());
        } else {
            System.out.println("调用失败");
        }

/*        <form name="punchout_form" method="post" action="https://openapi.alipaydev.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&sign=FwitHGhootWug0w%2F2N9yeh0a3yZeQ5qEHHauqAlQ0liGx2qV6BZmpYxhDVKd1FjNkmEoatHWoSfSiyhuWUbJCbtXDHHyf9MLNxEzliiWa09hMBHWl3FkJQzSiIv%2BccuhieaNyvOJSYVogfCQs4NON%2B%2FxTL9ol4nCeixjVcTfelRxVh3ZdUS64QnwgL4V6N2v5ncoERhb8S0arWMCkXOzkGZIpv%2Fc1aiMbdqTyRybx79XlE4ZohN3Snb2Dkeyxb5pTW8yII5jO510PxCjyBU1GZUMx4VQeFNkwhoopgMrMPlxkXI1wov1z7tfoVsi6j%2Bix%2BUB%2BasJs6dzW5CSIrIhqQ%3D%3D&version=1.0&app_id=2016102100732915&sign_type=RSA2&timestamp=2020-09-16+11%3A33%3A25&alipay_sdk=alipay-sdk-java-4.8.73.ALL&format=json">
<input type="hidden" name="biz_content" value="{&quot;out_trade_no&quot;:&quot;1600227003015&quot;,&quot;total_amount&quot;:&quot;12333.09&quot;,&quot;subject&quot;:&quot;支付宝测试付钱&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}">
<input type="submit" value="立即支付" style="display:none" >
</form>
<script>document.forms[0].submit();</script>*/
    }
}
